﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

//using BussinessObjects.BO_Actions;
//using Entity.StoreProcedure;
using LibraryO2S;
//using BusinessObjects.BO_GetObjects;
using System.Security.Cryptography;
using System.Net.Mail;
using System.IO;
using System.Xml;

public partial class administrator_ConfigIPServer : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ReadXMLFile();
        }
    }

    private void ReadXMLFile()
    {

        using (XmlTextReader reader = new XmlTextReader(Server.MapPath("config.xml")))
        {
            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.Text)
                {
                    txtserver.Text = reader.Value;
                }
            }
        }
    }
    private void WriteXMLToFile()
    {

        XmlTextWriter xmlwriter = new XmlTextWriter(Server.MapPath("config.xml"), System.Text.Encoding.UTF8);
        xmlwriter.Formatting = Formatting.Indented;
        xmlwriter.WriteStartDocument();
        xmlwriter.WriteStartElement("configs");

        xmlwriter.WriteStartElement("config");
        xmlwriter.WriteElementString("ip_1", txtserver.Text);
        xmlwriter.WriteEndElement();

        xmlwriter.WriteEndElement();
        xmlwriter.WriteEndDocument();
        xmlwriter.Flush();
        xmlwriter.Close();
    }
    //private bool WriteXMLToFile()
    //{
    //    try
    //    {
    //        XmlTextWriter xmlwriter = new XmlTextWriter("E:/config.xml", System.Text.Encoding.UTF8);
    //        xmlwriter.Formatting = Formatting.Indented;
    //        xmlwriter.WriteStartDocument();
    //        xmlwriter.WriteStartElement("configs");

    //        xmlwriter.WriteStartElement("config");
    //        xmlwriter.WriteElementString("ip_1", "");
    //        xmlwriter.WriteEndElement();

    //        xmlwriter.WriteEndElement();
    //        xmlwriter.WriteEndDocument();
    //        xmlwriter.Flush();
    //        xmlwriter.Close();
    //        return true;
    //    }
    //    catch (Exception)
    //    {

    //        return false;
    //    }


    //}
    protected void btnSend_Click(object sender, EventArgs e)
    {
        WriteXMLToFile();
        Response.Redirect("ControlPannel.aspx");

        //string server = txtserver.Text;
        //if (WriteXMLToFile())
        //{
        //    WriteXMLToFile(server);

        //    Response.Write("<script>alert('thanh cong')</script>");
        //}
        //else {

        //    Response.Write("<script>alert(' khong thanh cong')</script>");

        //}
    }
}
